package cn.javass.dp.command.example6;

public class HotCook implements CookApi ,Runnable{

    //厨师姓名
    private String name;

    public HotCook(String name) {
        this.name = name;
    }

    @Override
    public void cook(int tableNum, String name) {
        int cookTime = (int)(20 * Math.random());
        System.out.println(tableNum+"号桌热菜厨师"+this.name+"正在做" + name+"(菜名)");
        try {
            Thread.sleep(cookTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(tableNum+"号桌热菜厨师"+this.name+"正在做" + name+"(菜名)"+"用时"+cookTime+"秒");
    }

    @Override
    public void run() {
        //到队列去取出命令
        while (true) {
            Command cmd = CommandQueue.getOneCommand();
            if (cmd != null) {
                cmd.setCookApi(this);
                cmd.execute();
            }
            //休息一秒
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


    }
}
